<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hammerspoon docs: Leanpub</title>
    <style type="text/css">
      a { text-decoration: none; }
      a:hover { text-decoration: underline; }
      th { background-color: #DDDDDD; vertical-align: top; padding: 3px; }
      td { width: 100%; background-color: #EEEEEE; vertical-align: top; padding: 3px; }
      table { width: 100% ; border: 1px solid #0; text-align: left; }
      section > table table td { width: 0; }
    </style>
    <link rel="stylesheet" href="docs.css" type="text/css" media="screen" />
  </head>
  <body>
    <header>
      <h1><a href="./index.html">docs</a> &raquo; Leanpub</h1>
      <p>Spoon to track and notify about Leanpub builds.</p>
<p>Download:
https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Leanpub.spoon.zip</p>

      </header>
      <h3>API Overview</h3>
      <ul>
        <li>Variables - Configurable values</li>
          <ul>
            <li><a href="#api_key">api_key</a></li>
            <li><a href="#books_sync_to_dropbox">books_sync_to_dropbox</a></li>
            <li><a href="#check_interval">check_interval</a></li>
            <li><a href="#dropbox_path">dropbox_path</a></li>
            <li><a href="#dropbox_type">dropbox_type</a></li>
            <li><a href="#fetch_leanpub_covers">fetch_leanpub_covers</a></li>
            <li><a href="#logger">logger</a></li>
            <li><a href="#persistent_notification">persistent_notification</a></li>
            <li><a href="#watch_books">watch_books</a></li>
          </ul>
        <li>Methods - API calls which can only be made on an object returned by a constructor</li>
          <ul>
            <li><a href="#displayAllBookStatus">displayAllBookStatus</a></li>
            <li><a href="#displayBookStatus">displayBookStatus</a></li>
            <li><a href="#fetchBookCover">fetchBookCover</a></li>
            <li><a href="#getBookStatus">getBookStatus</a></li>
            <li><a href="#start">start</a></li>
            <li><a href="#stop">stop</a></li>
          </ul>
      </ul>
      <h3>API Documentation</h3>
        <h4 class="documentation-section">Variables</h4>
          <section id="api_key">
            <a name="//apple_ref/cpp/Variable/api_key" class="dashAnchor"></a>
            <h5><a href="#api_key">api_key</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.api_key</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>String containing the key to use for Leanpub API requests.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Get it from your Leanpub account under the &quot;Author / Your API Key&quot; menu section. No default.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L43">Source/Leanpub.spoon/init.lua line 43</a></td>
              </tr>
            </table>
          </section>
          <section id="books_sync_to_dropbox">
            <a name="//apple_ref/cpp/Variable/books_sync_to_dropbox" class="dashAnchor"></a>
            <h5><a href="#books_sync_to_dropbox">books_sync_to_dropbox</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.books_sync_to_dropbox</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Boolean that specifies whether all your books are being synced to Dropbox.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>If true, the &quot;Book generation complete&quot; notification will include a &quot;Show&quot; button to open the book's directory in Dropbox.</li>
<li>Setting this is equivalent to setting the <code>syncs_to_dropbox</code> attribute for each book in <code>watch_books</code>. Default value: <code>false</code>.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L34">Source/Leanpub.spoon/init.lua line 34</a></td>
              </tr>
            </table>
          </section>
          <section id="check_interval">
            <a name="//apple_ref/cpp/Variable/check_interval" class="dashAnchor"></a>
            <h5><a href="#check_interval">check_interval</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.check_interval</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Integer containing the interval (in seconds) at which the book status is checked. Default 5.</p>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L51">Source/Leanpub.spoon/init.lua line 51</a></td>
              </tr>
            </table>
          </section>
          <section id="dropbox_path">
            <a name="//apple_ref/cpp/Variable/dropbox_path" class="dashAnchor"></a>
            <h5><a href="#dropbox_path">dropbox_path</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.dropbox_path</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>String containing the base Dropbox path to which the books are synced, if the corresponding parameters are set.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>If unset, the path is determined automatically by reading the ~/.dropbox/info.json file and choosing the path corresponding to the profile specified in <code>Leanpub.dropbox_profile</code>.</li>
<li>If for some reason your synced files are somewhere else, you can store in this variable the final path to use. Most users should be fine with the defaults.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L72">Source/Leanpub.spoon/init.lua line 72</a></td>
              </tr>
            </table>
          </section>
          <section id="dropbox_type">
            <a name="//apple_ref/cpp/Variable/dropbox_type" class="dashAnchor"></a>
            <h5><a href="#dropbox_type">dropbox_type</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.dropbox_type</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>String containing the name of the Dropbox account type to use for determining the base path of the Dropbox directory.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Valid values are &quot;personal&quot; and &quot;business&quot;. See https://help.dropbox.com/installs-integrations/desktop/locate-dropbox-folder for the details.</li>
<li>Default value: &quot;personal&quot;.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L81">Source/Leanpub.spoon/init.lua line 81</a></td>
              </tr>
            </table>
          </section>
          <section id="fetch_leanpub_covers">
            <a name="//apple_ref/cpp/Variable/fetch_leanpub_covers" class="dashAnchor"></a>
            <h5><a href="#fetch_leanpub_covers">fetch_leanpub_covers</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.fetch_leanpub_covers</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Boolean indicating whether we should try to fetch book covers from Leanpub.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Default value: <code>true</code>.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L56">Source/Leanpub.spoon/init.lua line 56</a></td>
              </tr>
            </table>
          </section>
          <section id="logger">
            <a name="//apple_ref/cpp/Variable/logger" class="dashAnchor"></a>
            <h5><a href="#logger">logger</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.logger</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.</p>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L18">Source/Leanpub.spoon/init.lua line 18</a></td>
              </tr>
            </table>
          </section>
          <section id="persistent_notification">
            <a name="//apple_ref/cpp/Variable/persistent_notification" class="dashAnchor"></a>
            <h5><a href="#persistent_notification">persistent_notification</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.persistent_notification</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Table specifying the Leanpub status for which notifications should not disappear automatically.</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>The indices correspond to the values of the <code>status</code> field returned by the Leanpub API. Possible values are <code>working</code> and <code>complete</code>. Default <code>{ complete = true }</code> to keep the &quot;Book generation complete&quot; messages.</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L64">Source/Leanpub.spoon/init.lua line 64</a></td>
              </tr>
            </table>
          </section>
          <section id="watch_books">
            <a name="//apple_ref/cpp/Variable/watch_books" class="dashAnchor"></a>
            <h5><a href="#watch_books">watch_books</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub.watch_books</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Variable</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>List of books to watch (by default an empty list).</p>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Each element of the list must be a table containing the following keys:</li>
<li>slug - the web page &quot;slug&quot; of the book to watch. The slug of a book can be set under the &quot;Book Web Page / Web Page URL&quot; menu section in Leanpub.</li>
<li>icon - optional icon to show in the notifications for the book, as an hs.image object. If not specified, and if <code>fetch_leanpub_covers</code> is <code>true</code>, then the icon is generated automatically from the book cover.</li>
<li>syncs_to_dropbox - optional boolean to indicate whether the book is configured in Leanpub to sync to Dropbox (you can find this option in your books &quot;Writing mode&quot; screen, as &quot;Send output to Dropbox&quot;. If true, the &quot;Book generation complete&quot; notification will include a &quot;Show&quot; button to open the book's directory in Dropbox. If you have multiple books and all of them are synced to Dropbox, you can set the main <code>Leanpub.books_sync_to_dropbox</code> variable instead of setting it for each book. Default value: <code>false</code></li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L23">Source/Leanpub.spoon/init.lua line 23</a></td>
              </tr>
            </table>
          </section>
        <h4 class="documentation-section">Methods</h4>
          <section id="displayAllBookStatus">
            <a name="//apple_ref/cpp/Method/displayAllBookStatus" class="dashAnchor"></a>
            <h5><a href="#displayAllBookStatus">displayAllBookStatus</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:displayAllBookStatus()</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Check and display (if needed) the status of all the books in <code>watch_books</code></p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>None</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td></td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L282">Source/Leanpub.spoon/init.lua line 282</a></td>
              </tr>
            </table>
          </section>
          <section id="displayBookStatus">
            <a name="//apple_ref/cpp/Method/displayBookStatus" class="dashAnchor"></a>
            <h5><a href="#displayBookStatus">displayBookStatus</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:displayBookStatus(book)</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Display a notification with the current build status of a book.</p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>book - table containing the information of the book to check. The table must contain the following fields:<ul>
<li>slug - URL &quot;slug&quot; of the book to check. The slug is the part of the book URL after https://leanpub.com/.</li>
<li>icon - optional icon to show in the notifications for the book, as an <code>hs.image</code> object. If this field is not specified but <code>fetch_leanpub_covers</code> is true (the default value), this method attempts to fetch the book cover from Leanpub. If the cover can be retrieved, it gets stored in the icon field so it doesn't get fetched every time. You can disable cover fetching for individual books by setting this field explicitly to <code>false</code></li>
</ul>
</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td><ul>
<li>A Lua table containing the status (may be empty), nil if an error occurred</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Only produce a notification if the current status is different than the last known one (from the last time <code>displayBookStatus</code> was run for the same book).</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L144">Source/Leanpub.spoon/init.lua line 144</a></td>
              </tr>
            </table>
          </section>
          <section id="fetchBookCover">
            <a name="//apple_ref/cpp/Method/fetchBookCover" class="dashAnchor"></a>
            <h5><a href="#fetchBookCover">fetchBookCover</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:fetchBookCover(book)</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Fetch the cover of a book.</p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>book - table containing the book information. The icon gets stored in its <code>icon</code> field when it can be fetched.</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td><ul>
<li>No return value</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Notes</th>
                  <td><ul>
<li>Side effects:</li>
<li>Stores the icon in the book data structure</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L240">Source/Leanpub.spoon/init.lua line 240</a></td>
              </tr>
            </table>
          </section>
          <section id="getBookStatus">
            <a name="//apple_ref/cpp/Method/getBookStatus" class="dashAnchor"></a>
            <h5><a href="#getBookStatus">getBookStatus</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:getBookStatus(slug, callback)</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Asynchronously get the status of a book given its slug.</p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>slug - URL &quot;slug&quot; of the book to check. The slug of a book is the part of the URL for your book after https://leanpub.com/.</li>
<li>callback - function to which the book status will be passed when the data is received. This function will be passed a single argument, a table containing the fields returned by the Leanpub API. If the book is not being built at the moment, an empty table is passed. If an error occurs, the value passed will be <code>nil</code>. Samples of the return values can be found at https://leanpub.com/help/api#getting-the-job-status</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td><ul>
<li>No return value</li>
</ul>
</td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L107">Source/Leanpub.spoon/init.lua line 107</a></td>
              </tr>
            </table>
          </section>
          <section id="start">
            <a name="//apple_ref/cpp/Method/start" class="dashAnchor"></a>
            <h5><a href="#start">start</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:start()</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Start periodic check for book status, checking every check_interval seconds.</p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>None</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td></td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L296">Source/Leanpub.spoon/init.lua line 296</a></td>
              </tr>
            </table>
          </section>
          <section id="stop">
            <a name="//apple_ref/cpp/Method/stop" class="dashAnchor"></a>
            <h5><a href="#stop">stop</a></h5>
            <table>
              <tr>
                <th>Signature</th>
                <td><code>Leanpub:stop()</code></td>
              </tr>
              <tr>
                <th>Type</th>
                <td>Method</td>
              </tr>
              <tr>
                <th>Description</th>
                <td><p>Stops periodic check for book status, if enabled.</p>
</td>
              </tr>
              <tr>
                  <th>Parameters</th>
                  <td><ul>
<li>None</li>
</ul>
</td>
              </tr>
              <tr>
                  <th>Returns</th>
                  <td></td>
              </tr>
              <tr>
                <th>Source</th>
                <td><a href="https://github.com/Hammerspoon/Spoons/blob/master/Source/Leanpub.spoon/init.lua#L309">Source/Leanpub.spoon/init.lua line 309</a></td>
              </tr>
            </table>
          </section>
  </body>
</html>